/*
 * StringUtils.java
 *
 * Created on 1 maggio 2007, 12.48
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package fnUtils;

/**
 *
 * @author franic
 */

public final class StringUtils {
    public static String left(String text, int length) {
        if (length > 0) {
            return (text.length() < length) ? 
                text : 
                text.substring(0, length);
        } else {
            return text;
        }
    }
    
    public static String right(String text, int length) {
        if (length > 0) {
            return (text.length() < length) ?
                text :
                text.substring(text.length() - length, text.length());
        } else {
            return text;
        }
    }
    
    public static String mid(String text, int start, int length) {
        if (start > 0 && length > 0 && start + length < text.length()) {
            return (text.length() < length + 1) ?
                text.substring(start - 1, text.length()) :
                text.substring(start - 1, start + length - 1);
        } else {
            return text;
        }
    }
    
    public static String mid(String text, int start) {
        if (start > 0 && start < text.length()) {
            return (text.length() < start) ?
                "" :
                text.substring(start - 1, text.length());
        } else {
            return text;
        }
    }
}